﻿using MediatR;
using RedDragon.Common.Domain.MaterialManagements;
using RedDragon.Common.Infrastructure.Interface;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.Inventoryscheduling
{
    public class MaterialsSearchHandler : IRequestHandler<MaterialsSearchCommon, Result>
    {
        public readonly IBaseRepository<MaterialManagement> MaterialManagementRepository;

        public MaterialsSearchHandler(IBaseRepository<MaterialManagement> materialManagementRepository)
        {
            MaterialManagementRepository = materialManagementRepository;
        }

        public async Task<Result> Handle(MaterialsSearchCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = 0, Msg = "" };
            try
            {

                var list = MaterialManagementRepository.Query();
                if (request.Id != -1)
                {
                    MaterialManagementRepository.Query().Where(x => x.MaterialId == request.Id);
                }
                result.Data = list;
            }
            catch (Exception)
            {
                throw;
            }
            return result;
        }
    }
}
